package com.weathereport.helper;

import com.weathereport.R;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.EditText;

public class Checker {

	public static boolean isOnline(Context ctx) {
	    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(ctx.CONNECTIVITY_SERVICE);
	    NetworkInfo netInfo = cm.getActiveNetworkInfo();
	    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
	        return true;
	    }
	    return false;
	}

	public static boolean isNullOrEmpty(EditText editText) {
		boolean notOk = false;
		if (editText.getText().toString().equals("")) {
			editText.setError("Campo Obrigatório");
			editText.requestFocus();
			notOk = true;
		}
		return notOk;
	}

	public static boolean isNullOrEmpty(EditText... editTexts) {
		boolean notOk = false;
		for (EditText editText : editTexts) {
			if (isNullOrEmpty(editText)){
				notOk = true;
				return true;
			}
		}
		return notOk;
	}
}
